package com.moxiao.yfjh.module.maker.service.memberStringing;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.moxiao.yfjh.module.maker.dal.dataobject.memberStringing.MatchmakerMemberStringingDO;
import com.moxiao.yfjh.module.maker.dal.mysql.memberStringing.MatchmakerMemberStringingMapper;
import com.moxiao.yfjh.module.maker.service.MemberStringingApiService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 相亲红娘会员用户牵线总次数 Service 实现类
 *
 * @author mx
 */
@Service
@Validated
public class MemberStringingApiServiceImpl implements MemberStringingApiService {

    @Resource
    private MatchmakerMemberStringingMapper matchmakerMemberStringingMapper;

    @Override
    public int getSelectOne(Long userId) {
        LambdaQueryWrapper<MatchmakerMemberStringingDO> lqw = Wrappers.lambdaQuery();
        lqw.eq(MatchmakerMemberStringingDO::getMemberId, userId);
        lqw.last("LIMIT " + 1);
        MatchmakerMemberStringingDO memberStringingDO = matchmakerMemberStringingMapper.selectOne(lqw);
        if (Objects.nonNull(memberStringingDO)) {
            return memberStringingDO.getStringingNum();
        } else {
            return 0;
        }
    }


    @Override
    public int getIsMarker(Long userId) {
        LambdaQueryWrapper<MatchmakerMemberStringingDO> lqw = Wrappers.lambdaQuery();
        lqw.eq(MatchmakerMemberStringingDO::getMemberId, userId);
        lqw.last("LIMIT " + 1);
        MatchmakerMemberStringingDO memberStringingDO = matchmakerMemberStringingMapper.selectOne(lqw);
        if (Objects.nonNull(memberStringingDO)) {
            if (Objects.nonNull(memberStringingDO.getMatchmakerId())) {
                return 1;
            } else {
                return 0;
            }
        } else {
            return 0;
        }
    }
}
